home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / orca < prev    next >
Encoding:
Text File  |  2009-04-13  |  5.9 KB  |  181 lines

  1. #!/bin/bash
  2. #
  3. # Orca
  4. #
  5. # Copyright 2006-2008 Sun Microsystems Inc.
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Library General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. # Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Library General Public
  18. # License along with this library; if not, write to the
  19. # Free Software Foundation, Inc., Franklin Street, Fifth Floor,
  20. # Boston MA  02110-1301 USA.
  21.  
  22. # This script performs some clean up and will run Orca.  It will also
  23. # rerun Orca if it detects that Orca died an unnatural death.
  24.  
  25. # __id__        = "$Id: orca.in,v 1.22 2006/12/08 16:21:25 wwalker Exp $"
  26. # __version__   = "$Revision: 1.22 $"
  27. # __date__      = "$Date: 2006/12/08 16:21:25 $"
  28. # __copyright__ = "Copyright (c) 2006-2008 Sun Microsystems Inc."
  29. # __license__   = "LGPL"
  30.  
  31. # Set the user's $PATH for this script.
  32. #
  33. export PATH="${PATH}:/usr/bin:/usr/sbin:/bin:/usr/X11R6/bin"
  34.  
  35. # Save the arguments away.
  36. #
  37. ARGS="$*"
  38.  
  39. # Save away XMODMAP settings we might change.
  40. #
  41. saveXmodmap() 
  42. {
  43.     # We'll save and restore the Caps_Lock as a modifier just in case
  44.     # the user is using the Caps_Lock as the Orca modifier key.  We
  45.     # will also do so with the KP_Insert key since we want to make
  46.     # sure it only produces the keysyms we expect (it produces
  47.     # KP_Insert and KP_0 by default).  See the use of xmodmap in
  48.     # orca.py:loadUserSettings for the other part of what's going on.
  49.     # 
  50.     # [[[WDW: we probably should save/restore the autorepeat value of
  51.     # the Orca modifier key and turn the autorepeat off when Orca is
  52.     # running.  That can be done using the 'xset' utility, though
  53.     # turning it on/off is easy, but getting the current state is not
  54.     # straightforward.]]]
  55.     #
  56.     if [ "x$DISPLAY" != "x" ] ; then
  57.         CAPSLOCKSETTING=`xmodmap | grep Caps_Lock | cut -f1`
  58.         KPINSERTSETTING=`xmodmap -pke | grep KP_Insert`
  59.         INSERTSETTING=`xmodmap -pke | grep Insert | grep -v KP_`
  60.     fi
  61. }
  62.  
  63. # Restore XMODMAP settings we may have changed.
  64. #
  65. restoreXmodmap()
  66. {
  67.     if [ "x$CAPSLOCKSETTING" != "x" ] ; then
  68.         xmodmap -e "add $CAPSLOCKSETTING = Caps_Lock" > /dev/null 2>&1
  69.     fi
  70.     if [ "x$KPINSERTSETTING" != "x" ] ; then
  71.         xmodmap -e "$KPINSERTSETTING" > /dev/null 2>&1
  72.     fi
  73.     if [ "x$INSERTSETTING" != "x" ] ; then
  74.         xmodmap -e "$INSERTSETTING" > /dev/null 2>&1
  75.     fi
  76. }
  77.  
  78. # Cleans up any orca-related processes that might be running,
  79. # restricting it to those processes owned by the user. These include
  80. # orca itself, any gnome-speech synthesis drivers, and festival
  81. # processes running in server mode.
  82. #
  83. cleanup()
  84. {
  85.     USERID=`id | cut -f2 -d= | cut -f1 -d\(`
  86.     PIDS=`ps -eo pid,ruid,args | grep $USERID | \
  87.     egrep "orca[.]orca|OAFIID[:]GNOME_Speech|OAFIID[:]GNOME_Magnifier|festival [-][-]server"|\
  88.     grep -v grep | awk '{ print $1 }'`
  89.     IFS='
  90.     '
  91.     PIDS=`echo $PIDS`
  92.     if [ "x$PIDS" != "x" ] ; then
  93.         kill -9 $PIDS > /dev/null 2>&1
  94.     fi
  95.     restoreXmodmap
  96. }
  97.  
  98. trap cleanup HUP QUIT TERM INT ABRT
  99.  
  100. # Runs orca.
  101. #
  102. runOrca()
  103. {
  104.     saveXmodmap
  105.     exec /usr/bin/python -c "import orca.orca; orca.orca.main()" "$ARGS"
  106.     restoreXmodmap
  107. }
  108.  
  109. # Orca will fall into a text-based question and answer session if the
  110. # user has not configured orca and/or accessibility yet.  We will
  111. # force that to happen in the foreground (i.e., RUNONCE=true).  In
  112. # addition, if the user passes any command line arguments to orca, we
  113. # will run it in the foreground as well to avoid a situation where
  114. # orca dumps itself into the text-based setup utility.
  115. #
  116. # We make a special exception for gdm, which is used to handle the
  117. # accessible login.  If we're running as gdm, we assume everything is
  118. # all set and we don't need to muck around.
  119. #
  120. if [ "x$LOGNAME" != "xgdm" ] ; then
  121.     if [ "$1" = "-sudo" ]; then
  122.         shift
  123.         ACCESSIBILITY_ENABLED=`sudo -u "$1" gconftool-2 \
  124.         --get /desktop/gnome/interface/accessibility`
  125.         shift
  126.         ARGS="$*"
  127.     else
  128.         ACCESSIBILITY_ENABLED=`gconftool-2 \
  129.     --get /desktop/gnome/interface/accessibility`
  130.     fi
  131.     if [ "x$ACCESSIBILITY_ENABLED" != "xtrue" ] ; then
  132.         # Because we will be running Orca in text-setup mode, we want to
  133.         # make sure it is run in a terminal window.  If we're already in
  134.         # a terminal, this is great.  If not, we spawn a gnome-terminal
  135.         # and run orca in it.
  136.         #
  137.         tty -s && IN_TTY="true" || IN_TTY="false"
  138.         if [ "x$IN_TTY" = "xfalse" ] ; then
  139.             exec gnome-terminal -x $0 $ARGS
  140.         exit
  141.         fi
  142.     fi
  143. fi
  144.  
  145. if echo "$ARGS" | grep -- "-q" > /dev/null; then
  146.     # If the user has done -q or --quit, that means to tell any
  147.     # existing orca process to quit.  So, we just do a cleanup.
  148.     #
  149.     cleanup
  150. else
  151.     # If the user passed in a flag that results in orca only
  152.     # outputting data to the console, don't kill any other orca
  153.     # process.  We do this by looking for flags that *should* result
  154.     # in a cleanup (i.e., every legal command except -?, --help, -v,
  155.     # --version, -l, and --list-apps).  This way, if the user
  156.     # erroneously types an illegal command line argument, the help
  157.     # text is emitted and the other orca is not killed.
  158.     #
  159.     if [ "x$ARGS" = "x" ] ; then
  160.         CLEANUP=1
  161.     else
  162.         CLEANUP=`egrep -c "\-s|\-t|\-n|\-u|\-e|\-d" <<< $ARGS`
  163.     fi
  164.  
  165.     # Clean up before running orca to get anything that might
  166.     # be laying around.
  167.     #
  168.     if [ $CLEANUP -gt 0 ] ; then
  169.     cleanup
  170.     fi
  171.  
  172.     runOrca
  173.  
  174.     # Clean up after running orca in case things were not 
  175.     # shutdown cleanly (e.g., speech).
  176.     #
  177.     if [ $CLEANUP -gt 0 ] ; then
  178.     cleanup
  179.     fi
  180. fi
  181.